def is_prime(a):
    for y in range(2, int(a ** 0.5) + 1):
        if a % y == 0:
            return False
    return True


a = input().split()
f = 1
sl = {"zero": "0", "one": "1", "two": "2", "three": "3", "four": "4", "five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9"}
if a[0] not in sl or a[1] not in sl or a[2] not in sl:
    print("Wrong input")
else:
    a = int(sl[a[0]] + sl[a[1]] + sl[a[2]])
    while True:
        if is_prime(a - f):
            print(a - f)
            break
        elif is_prime(a + f):
            print(a + f)
            break
        f += 1